{{template "base/base.html" .}}
{{template "base/base_common.html" .}}
{{define "meta"}}
    <title>{{.Topic.Name}} - {{i18n .Lang "app_name"}}</title>
    <meta name="description" content="{{.Topic.Intro}}" />
{{end}}
{{define "body"}}
<div class="row">
    <div id="content" class="col-md-9">
    	<div class="box">
            <ol class="breadcrumb first">
                <li><a href="{{.AppUrl}}"><span class="glyphicon glyphicon-home"></span></a></li>
                <li><a href="{{.Category.Link}}">{{.Category.Name}}</a></li>
                <li><a href="{{.Topic.Link}}">{{.Topic.Name}}</a></li>
            </ol>
            <div class="topic-info">
                <div class="topic-img pull-left">
                    <img src="{{.Topic.ImageLink}}">
                </div>
                <div class="topic-intro">
                    {{str2html (.Topic.Intro)}}
                </div>
                <div class="topic-meta">
                    <div class="pull-left">
                        {{if .Topic.Followers}}
                        <div class="input-group input-group-sm">
                            <span class="input-group-btn">
                        {{end}}
                        {{if .IsLogin}}
                            {{if .HasFavorite}}
                                <button rel="do-favorite" class="btn btn-default btn-sm active"><span class="glyphicon glyphicon-star"></span> {{i18n .Lang "topic.favorite_remove"}}</button>
                            {{else}}
                                <button rel="do-favorite" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-star-empty"></span> {{i18n .Lang "topic.favorite_add"}}</button>
                            {{end}}
                        {{else}}
                            <a class="btn btn-default btn-sm" href="{{loginto .Topic.Link}}"><span class="glyphicon glyphicon-star-empty"></span> {{i18n .Lang "topic.favorite_add"}}</a>
                        {{end}}
                        {{if .Topic.Followers}} </span><span class="input-group-addon">{{.Topic.Followers}} {{i18n .Lang "topic.favorite_already"}}</span></div>{{end}}
                    </div>
                    <div class="pull-right">
                        {{if .IsLogin}}
                            <a class="btn btn-primary btn-sm" href="{{.AppUrl}}new?topic={{.Topic.Slug}}"><i class="icon-chevron-sign-up"></i> {{i18n .Lang "post.post_new"}}</a>
                        {{else}}
                            <a class="btn btn-primary btn-sm" href="{{loginto (print .AppUrl "new?topic=" .Topic.Slug)}}"><i class="icon-chevron-sign-up"></i> {{i18n .Lang "post.post_new"}}</a>
                        {{end}}
                    </div>
                </div>
                <span class="clearfix"></span>
            </div>
            {{if .paginator.Nums}}
                <div class="post-list">
                    {{template "post/component/posts.html" dict "root" . "Posts" .Posts}}
                </div>
        		<div class="last">
                    {{template "base/paginator_pn.html" .}}
                </div>
            {{else}}
                <div class="last">
                    <div class="text-center">{{i18n .Lang "postnav.not_found_posts"}}</div>
                </div>
            {{end}}
    	</div>
	</div>
    <div id="sidebar" class="col-md-3">
        
    </div>
</div>
<script type="text/javascript">
    (function($){
        $(document).on("click", "[rel=do-favorite]", function(){
            var $btn = $(this);
            $btn.button("loading");
            $.post("{{.Topic.Link}}", {action: "favorite"}, function(data){
            }).complete(function(){
                window.location.reload();
            });
        });
    })(jQuery);
</script>
{{end}}